package com.android.fragmentdemo.thread19
import org.junit.Test
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit

class Demo19 {
    @Test
    fun testRunnable() {
        val ses = Executors.newScheduledThreadPool(3)
        //延迟时间执行
        //ses.schedule(MyRunnable(), 1, TimeUnit.SECONDS)

        //间隔周期执行任务
        //ses.scheduleAtFixedRate(MyRunnable(), 1, 3, TimeUnit.SECONDS)

        //固定延时执行任务
        ses.scheduleWithFixedDelay(MyRunnable(), 3, 3, TimeUnit.SECONDS)

        Thread.sleep(12 * 1000)
    }

    class MyRunnable :  Runnable {
        override fun run() {
            println("执行了线程:${Thread.currentThread().name}")
        }
    }
}